﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.DAL
{
    class StockInBill:IStockInBill
    {
        #region IStockInBill 成员

        public IDataReader Select(string StockInNum)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public DataTable Select()
        {
            try
            {
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_StockInBill_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public DataTable Select(int PageIndex, int PageSize, string StockInTypeName, string StockInNum)
        {
            try
            {
                SqlParameter [] all=new SqlParameter[]
                {
                    new SqlParameter("@PageIndex",PageIndex),
                    new SqlParameter("@PageSize",PageSize),
                    new SqlParameter("@StockInTypeName",StockInTypeName),
                    new SqlParameter("@StockInNum",StockInNum)                
                };
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_StockInBill_Filter", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Insert(string StockInNum, string StockInTypeNum, DateTime StockInDatetime, int DrugNum, int Quantity, float TotalPrice, string ApprovalBy, DateTime ApprovalDatetime, string Remark)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockInNum",StockInNum),
                    new SqlParameter("@StockInTypeNum",StockInTypeNum),
                    new SqlParameter("@StockInDatetime",StockInDatetime),
                    new SqlParameter("@DrugNum",DrugNum),
                    new SqlParameter("@Quantity",Quantity),
                    new SqlParameter("@TotalPrice",TotalPrice),
                    new SqlParameter("@ApprovalBy",ApprovalBy),
                    new SqlParameter("@ApprovalDatetime",ApprovalDatetime),
                    new SqlParameter("Remark",Remark)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Update(string StockInNum, string StockInTypeNum, DateTime StockInDatetime, int DrugNum, int Quantity, float TotalPrice, string ApprovalBy, DateTime ApprovalDatetime, string Remark)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockInNum",StockInNum),
                    new SqlParameter("@StockInTypeNum",StockInTypeNum),
                    new SqlParameter("@StockInDatetime",StockInDatetime),
                    new SqlParameter("@DrugNum",DrugNum),
                    new SqlParameter("@Quantity",Quantity),
                    new SqlParameter("@TotalPrice",TotalPrice),
                    new SqlParameter("@ApprovalBy",ApprovalBy),
                    new SqlParameter("@ApprovalDatetime",ApprovalDatetime),
                    new SqlParameter("Remark",Remark)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Delete(string StockInNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "", new SqlParameter[] { new SqlParameter("@StockInNum", StockInNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        #endregion
    }
}
